package com.fanxuankai.boot.canal.client.autoconfigure;

import com.fanxuankai.boot.canal.client.CanalWorker;
import com.fanxuankai.boot.canal.client.MessageConsumer;
import com.fanxuankai.boot.canal.client.OtterClient;
import com.fanxuankai.commons.util.concurrent.ScheduledThreadPool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author fanxuankai
 */
@Configuration
@EnableConfigurationProperties({CanalClientProperties.class})
@ConditionalOnProperty(name = CanalClientProperties.ENABLED, matchIfMissing = true)
public class CanalClientAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    public ScheduledThreadPoolExecutor scheduledThreadPoolExecutor() {
        return ScheduledThreadPool.INSTANCE.getExecutor();
    }

    @Bean
    public CanalWorker canalWorker() {
        return new CanalWorker();
    }

    @Bean
    public OtterClient otterClient() {
        return new OtterClient();
    }

    @Bean
    public MessageConsumer messageConsumer() {
        return new MessageConsumer();
    }
}
